import 'package:flutter/material.dart';

///自定义dialog
class CustomDialog extends Dialog {
  final String title;
  final String content;
  Function()? onClosed;

  CustomDialog(
      {super.key, required this.title, required this.content, this.onClosed});

  @override
  Widget build(BuildContext context) {
    return Material(
      //dialog为透明背景
      type: MaterialType.transparency,
      child: Center(
        child: Container(
          height: 300,
          width: 300,
          color: Colors.white,
          child: Column(
            children: [
              Padding(
                padding: EdgeInsets.all(10),
                child: Stack(
                  children: [
                    Align(alignment: Alignment.center, child: Text(title)),
                    Align(
                      alignment: Alignment.centerRight,
                      child: InkWell(
                        onTap: onClosed,
                        child: Icon(Icons.close,),
                      ),
                    ),
                  ],
                ),
              ),
              Divider(),
              Container(
                padding: EdgeInsets.all(10),
                width: double.infinity,
                child: Text(content, textAlign: TextAlign.left),
              )
            ],
          ),
        ),
      ),
    );
  }
}
